import store from '@/store'
import Config from "@/settings";
export default {
  inserted(el, binding) {
    if (Config.permissionType == 'menu') {
      return;
    }
    const { value } = binding
    const permissions = store.getters && store.getters.permissions
    console.info(permissions)
    if (value && value instanceof Array) {
      if (value.length > 0) {
        const permissionRoles = value

        const hasPermission = permissions.some(role => {
          return permissionRoles.includes(role) || role == '*'
        })

        if (!hasPermission) {
          el.parentNode && el.parentNode.removeChild(el)
        }
        console.debug("roles:" + permissions)
      }
    } else {
      throw new Error(`使用方式： v-permission="['admin','editor']"`)
    }
  }
}
